package com.ruoyi.web.controller.archive;

import cn.hutool.core.date.DateUtil;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.domain.PProduct;
import com.ruoyi.system.service.IPProductService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品管理Controller
 * 
 * @author ruoyi
 * @date 2024-12-31
 */
@RestController
@RequestMapping("/archive/product")
public class PProductController extends BaseController
{
    @Autowired
    private IPProductService pProductService;

    /**
     * 查询商品管理列表
     */
    @PreAuthorize("@ss.hasPermi('archive:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(PProduct pProduct)
    {
        startPage();
        List<PProduct> list = pProductService.selectPProductList(pProduct);
        return getDataTable(list);
    }

    @GetMapping("/getList")
    public AjaxResult getList(PProduct pProduct)
    {
        return success(pProductService.selectPProductList(pProduct));
    }


    /**
     * 导出商品管理列表
     */
    @PreAuthorize("@ss.hasPermi('archive:product:export')")
    @Log(title = "商品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PProduct pProduct)
    {
        List<PProduct> list = pProductService.selectPProductList(pProduct);
        ExcelUtil<PProduct> util = new ExcelUtil<PProduct>(PProduct.class);
        util.exportExcel(response, list, "商品管理数据");
    }

    /**
     * 获取商品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('archive:product:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pProductService.selectPProductById(id));
    }



    @GetMapping(value = "/getInfo/{cabinetId}/{boxNo}")
    public AjaxResult getInfoByCabinetId(@PathVariable("cabinetId") Long cabinetId,@PathVariable("boxNo") Long boxNo)
    {
        return success(pProductService.getInfoByCabinetId(cabinetId,boxNo));
    }

    /**
     * 新增商品管理
     */
    @PreAuthorize("@ss.hasPermi('archive:product:add')")
    @Log(title = "商品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PProduct pProduct)
    {
        return toAjax(pProductService.insertPProduct(pProduct));
    }

    /**
     * 修改商品管理
     */
    @PreAuthorize("@ss.hasPermi('archive:product:edit')")
    @Log(title = "商品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PProduct pProduct)
    {
        return toAjax(pProductService.updatePProduct(pProduct));
    }

    /**
     * 删除商品管理
     */
    @PreAuthorize("@ss.hasPermi('archive:product:remove')")
    @Log(title = "商品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pProductService.deletePProductByIds(ids));
    }
}
